package com.geline.sqlbackup.druid;

import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor;
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
import com.geline.sqlbackup.bean.TableColumnInfo;
import com.geline.sqlbackup.thirdjar.SqlServerType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author mengx
 * @date 2020/12/28 17:28
 */
public class PostgreSQLDdlSqlHandler implements DdlSqlHandler {
    private static final Logger log = LoggerFactory.getLogger(PostgreSQLDdlSqlHandler.class);

    @Override
    public TableColumnInfo handler(String ddlSql, List<String> ignoredColumnList, boolean useRemoveTableHead, boolean useCamelCase) {
        throw new UnsupportedOperationException();
    }

    @Override
    public SchemaStatVisitor initSchemaStatVisitor() {
        return new PGSchemaStatVisitor();
    }

    @Override
    public Integer getVendorTypeNumber(String columnName, String dataType) {
        SqlServerType dbType = SqlServerType.valueOf(dataType.toUpperCase());
        if(null == dbType){
            String msg = String.format("Invalid field type in SqlServer ! %s [%s]", columnName, dataType);
            log.warn(msg);
            throw new RuntimeException(msg);
        }
        return dbType.getVendorTypeNumber();
    }

    @Override
    public String getJavaType(String columnName, String dataType) {
        return null;
    }
}
